/**
 * Created by yubaolin on 2017/9/14.
 */
import ajax from '../ajax'

export default {
  getApiList (params, success, fail = null) {
    ajax.get({
      url: `/api/action/apiList`,
      params: params,
      success,
      fail
    })
  },
  saveApi (apiData, success, fail = null) {
    const method = apiData.id === 0 ? 'post' : 'put'
    ajax[method]({url: `/api/action/${apiData.id}`, data: apiData, success, fail})
  },
  deleteApi (apiId, success) {
    ajax.del({url: `/api/action/${apiId}`, success})
  },
  deleteApis (apiIds, success) {
    ajax.del({url: `/api/action/deleteList`, data: {ids: apiIds}, success})
  },
  getRoleApiListAction (params, success, fail = null) {
    ajax.get({url: '/api/action/roleApiList', params, success, fail})
  },
  getNotApiListAction (params, success, fail = null) {
    ajax.get({url: '/api/action/notRoleApiList', params, success, fail})
  },
  saveRoleApi (roleId, actions, success, fail = null) {
    ajax.post({url: '/api/action/saveRoleApi', data: {roleId, actions}, success, fail})
  },
  deleteRoleApi (roleId, actionIds, success, fail = null) {
    ajax.del({url: '/api/action/deleteRoleApi', data: {roleId, actionIds}, success, fail})
  }
}
